import express from "express";
import transactionsRouter from "./routes/transactions";
import proxyToRepChainRouter from "./routes/proxyToRepChain";
import apiDocsRouter from "./routes/apiDocs";
import logger from "./log";
import myConfig from "./config";
import handleErrorsUncaught from "./errorsUncaughtHandler";

const app = express();
const port = process.env.PORT || myConfig.port || 5000;
app.use(express.json());

app.use("/transactions", transactionsRouter, handleErrorsUncaught);
const { enableSwaggerDoc = true, enableReverseProxy = true } = myConfig;
if (enableSwaggerDoc) {
    app.use("/apiDocs", apiDocsRouter, handleErrorsUncaught);
}

if (enableReverseProxy) {
    app.use("/", proxyToRepChainRouter, handleErrorsUncaught);
}

app.listen(port, () => {
    logger.info(`Web server powered by Express is listening on port: ${port}`);
});
